package leetcode

/*
 * @lc app=leetcode.cn id=705 lang=golang
 *
 * [705] 设计哈希集合
 */

// @lc code=start
// const base = 769

// MyHashSet ...
type MyHashSet struct {
	data [769][]int
}

// ConstructorMyHashSet ...
/** Initialize your data structure here. */
func ConstructorMyHashSet() MyHashSet {
	return MyHashSet{}
}

// Add ...
func (hs *MyHashSet) Add(key int) {
	h := key % base
	if lst := hs.data[h]; lst == nil {
		hs.data[h] = make([]int, 0)
	}
	for _, v := range hs.data[h] {
		if v == key {
			return
		}
	}
	hs.data[h] = append(hs.data[h], key)
}

// Remove ...
func (hs *MyHashSet) Remove(key int) {
	h := key % base
	for i, v := range hs.data[h] {
		if v == key {
			hs.data[h] = append(hs.data[h][:i], hs.data[h][i+1:]...)
		}
	}
}

// Contains ...
/** Returns true if hs set contains the specified element */
func (hs *MyHashSet) Contains(key int) bool {
	h := key % base
	for _, v := range hs.data[h] {
		if v == key {
			return true
		}
	}
	return false
}

/**
 * Your MyHashSet object will be instantiated and called as such:
 * obj := Constructor();
 * obj.Add(key);
 * obj.Remove(key);
 * param_3 := obj.Contains(key);
 */
// @lc code=end
